﻿@model article_forecast

@{
    ViewData["title"] = "预测详情";
    ViewData["container-css"] = "col-md-12";
    var art = Model;
    var sex = art.sex ? 1 : 2;
    art.born_date = art.born_date.ToLocalTime();
    var baziHref = $"https://www.smxs.com/bazi/index.html?submit=1&xingming=&yearType=1&sdYear={art.born_date.Year}&sdMonth={art.born_date.Month}&sdDay={art.born_date.Day}&hour={art.born_date.Hour}&minute={art.born_date.Minute}&sex={sex}";
}

<div class="row">
    <form id="ajaxForm" enctype="multipart/form-data" class="form-horizontal">
        <input type="hidden" name="id" value="@art.id.ToString()" />
        <div class="container-fluid">
            <div class="row form-group">
                <label class="control-label col-md-1">申请人</label>
                <div class="col-md-8">
                    <input class="form-control" name="user_nick_name" id="user_nick_name" type="text" value="@art.user_nick_name" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">姓名</label>
                <div class="col-md-8">
                    <input class="form-control" name="name" id="name" type="text" value="@art.name" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">性别</label>
                <div class="col-md-8">
                    <input class="form-control" id="name" type="text" value="@(art.sex ? "男" : "女")" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">生日(阳历)</label>
                <div class="col-md-8">
                    <input class="form-control" name="born_date" id="born_date" type="text" value="@art.born_date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">出生地</label>
                <div class="col-md-8">
                    <input class="form-control" name="born_place" id="born_place" type="text" value="@art.born_place" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">标题</label>
                <div class="col-md-8">
                    <input class="form-control" name="title" id="title" type="text" value="@art.title" />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-1">八字</label>
                <div class="col-md-8">
                    <input class="form-control" name="horoscope_8char" id="horoscope_8char" type="text" value="@art.horoscope_8char" />
                    <a href="@baziHref" target="_blank">查看排盘结果</a>
                    <label>@art.born_date.ToLocalTime().GetBaZi().Replace("-", "")</label>
                </div>
            </div>

            <div class="row form-group">
                <label class="control-label col-md-1">预测结果</label>
                <div class="col-md-8">
                    <div id="editor">
                        @{
                            if (string.IsNullOrWhiteSpace(art.horoscope_result))
                            {

                            }
                            else
                            {
                                @Html.Raw(art.horoscope_result)
                            }
                        }
                    </div>
                </div>
                <div class="col-md-3">
                    <pre>@Html.Raw(art.born_date.ToLocalTime().GetBaZi().Replace("-", "").GetBaziWuXing())</pre>
                </div>
            </div>

            <div class="row form-group">
                <label class="control-label col-md-1">是否显示</label>
                <div class="col-md-8">
                    <input class="i-checks" name="is_show" id="is_show" type="checkbox" value="true" @(art.is_show ? "checked" : string.Empty) />
                </div>
            </div>

            <div class="row form-group">
                <label class="control-label col-md-1">修改人</label>
                <div class="col-md-8">
                    <input class="form-control" name="change_user" id="change_user" type="text" value="@art.change_user" readonly />
                </div>
            </div>

            <div class="row form-group">
                <label class="control-label col-md-1">修改时间</label>
                <div class="col-md-8">
                    <input class="form-control" name="last_update" id="last_update" type="text" value="@art.last_update.ToLocalTime().ToLocalDateTimeString()" readonly />
                </div>
            </div>

            <div class="row form-group">
                <div class="col-md-6 col-md-offset-1">
                    <button type="button" class="btn btn-primary" onclick="SaveResurt()">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>

@section scripts{

    <script type="text/javascript">
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        // editor.customConfig.uploadImgShowBase64 = true
        // 将图片大小限制为 3M
        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editor.customConfig.uploadImgServer = '/upload/image'
        // 限制一次最多上传 5 张图片
        editor.customConfig.uploadImgMaxLength = 5
        editor.customConfig.uploadFileName = 'image'
        editor.create();

        E.fullscreen.init(editor);
        E.viewSource.init(editor);

        function SaveResurt() {
            if ($("#horoscope_8char").val().length == 0) {
                utils.ShowError("请输入八字");
                return;
            }
            if ($("#title").val().length == 0) {
                utils.ShowError("请输入标题");
                return;
            }
            if (editor.txt.text().length == 0) {
                utils.ShowError("请输入预测结果");
                return;
            }

            $("#ajaxForm").ajaxSubmit({
                type: 'post',
                url: '@Url.Action(nameof(DivinationController.UpdateDivination))',
                data: {
                    horoscope_result: editor.txt.html()
                },  // data是作为额外提交的表单数据
                success: function (e) {
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.reload(true);
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.msg);
                }
            });
        }
    </script>
}
